<?php
/**
 * Created by lzl
 * Date: 2021 2021/10/18
 * Time: 13:20
 */
namespace App\Plugins\Controllers\Api;

use App\Plugins\Forms\ShareFreeForms;
use App\Plugins\Services\Api\ShareFreeOrderServices;

class ShareFreeOrderController extends BaseController
{

    /**
     * 生成订单
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function generate()
    {
        $rules = [
            'share_id' => 'required',
            'order_id' => 'nullable', //存在即为受邀进来
        ];

        $this->validateInput($rules);

        return $this->success((new ShareFreeOrderServices())->generateOrder($this->validated));


    }


    /**
     * 助力
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function share()
    {
        $rules = [
            'order_id' => 'required',
        ];

        $this->validateInput($rules);

        return $this->success((new ShareFreeOrderServices())->dealShare($this->validated));
    }



    /**
     * 免费拿列表
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function shareList()
    {
        $rules = [
            'page'  => 'required|integer',
            'limit' => 'required|integer',
        ];

        $this->validateInput($rules);

        return $this->successOrNodata((new ShareFreeForms())->getShareGoodsList($this->validated));

    }


    /**
     * 确认下单
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function confirmPreview()
    {
        $rules = [
            'order_id' => 'required',
        ];

        $this->validateInput($rules);

        return $this->success((new ShareFreeOrderServices())->confirmPreview($this->validated['order_id']));

    }


}